package com.corgi.test.java8.time;

import lombok.extern.slf4j.Slf4j;

import java.time.LocalTime;
import java.time.temporal.ChronoUnit;

/**
 * @title: NewLocalTime
 * @description:
 * @author: dengmiao
 * @create: 2019-11-15 12:02
 **/
@Slf4j
public class NewLocalTime {

    public static void main(String[] args) {
        // 从系统时钟创建当前LocalTime
        LocalTime now = LocalTime.now();
        log.info("现在是: .now() => {}", now);

        // 反格式化获取时间
        LocalTime ofNow = LocalTime.of(12, 30);
        LocalTime parseNow = LocalTime.parse("12:30");
        log.info("现在是: .of() => {}, .parse() => {}", ofNow, parseNow);

        // 时间加减 尝试加一天异常
        LocalTime nextHour = now.plus(1, ChronoUnit./*DAYS*/HOURS);
        LocalTime nextMinute = now.plusMinutes(1);
        LocalTime preSecond = now.minusSeconds(1);
        log.info("一小时后是: {}, 一分钟后是: {}, 一秒前是: {}", nextHour, nextMinute, preSecond);

        // 获取时间的时间单位 多少小时 分钟 秒
        int hour = now.getHour(), minute = now.getMinute(), second = now.getSecond(), nano = now.getNano();
        log.info("现在是: {}时 {}分 {}秒 {}毫微秒", hour, minute, second, nano);

        // 判断时间先后
        boolean isbefore = now.isBefore(LocalTime.parse("12:30"));
        boolean isafter = now.isAfter(LocalTime.parse("12:30"));
        log.info("{} {}", isbefore, isafter);

        LocalTime maxTime = LocalTime.MAX;
        log.info("{}", maxTime);
    }
}
